# pip install fastapi 快速实现一个自己想要的api
# 使用介绍https://www.jianshu.com/p/d01d3f25a2af
import random
from typing import Optional

from fastapi import FastAPI
# python启用api，需要安装好uvicorn
# pip install uvicorn
# https://www.cnblogs.com/kknote/p/14985301.html
import uvicorn

app = FastAPI()


@app.get('/')
def index():
    return {'message': '你已经正确创建 FastApi 服务！'}


# 带参数的get请求
@app.get('/queryTest')  # uid: Optional[str] = None  uid->参数名 Optional[str]->参数类型  = None -> 默认值
def query(uid: Optional[str] = None):
    msg = f'你查询的 uid 为：{uid}'
    return {'success': True, 'msg': msg}


if __name__ == '__main__':
    uvicorn.run(app='main_api:app', host="192.168.42.109", port=8001, reload=True, debug=True)

